<%--
  Created by IntelliJ IDEA.
  User: zk
  Date: 2017/11/9
  Time: 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>

<blockquote class="layui-elem-quote">${title}</blockquote>
<form class="layui-form" action="${ctx}/sys/user/save" lay-filter="userList" data-pjax >
    <input type="hidden" value="${user.id}" name="id">
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label ">登录账号</label>
                <div class="layui-input-block ">
                    <input value="${user.name}" type="text" name="name" lay-verify="required" lay-verType="tips"
                           placeholder="请输入登录账号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">密码</label>
                <div class="layui-input-inline ">
                    <input id="newPassword"  type="text" name="newPassword" lay-verify="password" lay-verType="tips"
                           placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
                <c:if test="${not empty user.id}">
                    <div class="layui-form-mid layui-word-aux">若不修改密码，不填写</div>
                </c:if>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">手机号</label>
                <div class="layui-input-block ">
                    <input value="${user.mobile}" type="text" name="mobile" lay-verify="phone|number" lay-verType="tips"
                           placeholder="请输入手机号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">请选择角色</label>
                <div class="layui-input-block">
                    <c:forEach items="${roleList}" var="ro">
                        <input type="checkbox" name="roleIds" value="${ro.id}" title="${ro.zhName}" ${fns:inString(ro.id, user.roleIds)?'checked':''}>
                    </c:forEach>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-md6">

            <div class="layui-form-item">
                <label class="layui-form-label ">昵称</label>
                <div class="layui-input-block ">
                    <input value="${user.nickname}"  name="nickname" lay-verify="required" lay-verType="tips"
                           placeholder="请输入昵称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">确认密码</label>
                <div class="layui-input-inline">
                    <input id="confirmPassword" lay-verify="confirmPassword" name=confirmPassword" lay-verType="tips" placeholder="请确认密码" autocomplete="off"
                           class="layui-input">
                </div>
                <c:if test="${not empty user.id}">
                    <div class="layui-form-mid layui-word-aux">若不修改密码，不填写</div>
                </c:if>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">邮箱</label>
                <div class="layui-input-block ">
                    <input value="${user.email}" type="text" name="email" lay-verify="required|email" lay-verType="tips"
                           placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">账户状态</label>
                <div class="layui-input-block ">
                    <input type="checkbox" name="loginFlag" value="${user.loginFlag}" lay-skin="switch" lay-text="正常|禁用" lay-filter="loginFlag" ${0 eq user.loginFlag ? 'checked': ''}>
                </div>
            </div>

        </div>
    </div>
    <div class="layui-row">
        <br><br>
        <div class="layui-form-item">
            <div class="layui-input-block ">
                <button class="layui-btn" lay-submit="" lay-filter="userSave">${empty user.id?'添加':'修改'}</button>
                <a class="layui-btn layui-btn-primary" href="${ctx}/sys/user/" data-pjax>返回</a>
            </div>
        </div>
    </div>
</form>

<script>
    //    layui.use(['form','jquery','element'],function(){
    //        //无需再执行layui.use()方法加载模块，直接使用即可
    //
    //    });
    $(function () {
        var form = layui.form;
        form.verify({
            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            password: function(value, item) {
                var isVerify = false;
                if(${empty user.id}){
                    isVerify = true;
                }
                if(value!=null&&value!=''){
                    isVerify = true;
                }
                if(isVerify&&!/^[\S]{6,12}$/.test(value))
                    return'密码必须6到12位，且不能出现空格';
            },
            confirmPassword: function(value, item) { //value：表单的值、item：表单的DOM对象
                var newPass = $('#newPassword').val();
                var isVerify = false;
                if(${empty user.id}){
                    isVerify = true;
                }
                if(newPass!=null&&newPass!=''){
                    isVerify = true;
                }
                if(isVerify){
                    if(value==null||value==''){
                        return '请再次输入密码';
                    }else if(value!=newPass){
                        return '密码不一致请重新输入';
                    }
                }
            }
        });
        form.render();
        form.on('switch(loginFlag)', function(data){
            this.value = data.elem.checked?'0':'1';
        });
    });
</script>